﻿@model BookDetailsViewModel

@helper GeneratePersonPanel(BookSubscriptionViewModel subscription, bool isWaitingList)
	{
		string commonTooltipUrl = Url.Action("GetGenericTooltip", "Tooltip");

		if ((bool)Session["isAdmin"])
		{
			@Html.Partial("AdminPanel", subscription)
			<span class="icon adminPanelIcon smallIcon">&nbsp;</span>
		}

		<span class="icon clockIcon smallIcon" data-tooltip-url="@Url.Action("GetPersonTimeTooltip", "Tooltip")" data-tooltip-id="genericTooltip">&nbsp;</span>
	
		if ((!(bool)Session["isAdmin"] && Model.IsInWaitingList && subscription.PersonID == Model.AuthenticatedUserID && isWaitingList))
		{
			<span class="icon crossIcon smallIcon" data-postback="@Url.Action("DeleteSubscriptions", "Library")" data-tooltip-url="@commonTooltipUrl" data-tooltip-type="@((int)TooltipType.DeleteAllInfo)" data-tooltip-id="genericTooltip">&nbsp;</span>
		}

		<span class="peopleName" data-tooltip-url="@Url.Action("GetPersonInfoTooltip", "Tooltip")" data-person-id="@subscription.PersonID" data-tooltip-id="personInfoTooltip">@subscription.PersonCommonName</span>
}
<div class="bookDetailsContainer">
<div class="peopleWrapper">

	<div class="listTitle">Readers:</div>

	<ul class="peopleList" data-list-mode="@((int)Model.HistoryListMode)" data-list-name="historyList">
		@if (Model.Reader != null)
		{
			<li class="reader" data-subscription-set="@Model.Reader.SubscriptionSet">
				@GeneratePersonPanel(Model.Reader, false)
				
				@if ((bool)Session["isAdmin"])
				{
					<span class="icon smallIcon smallEditIcon" data-state="@((int) SubscribeState.Reader)" data-postback="@Url.Action("AddSubscriptionAdmin", "Library")" data-tooltip-type="@((int) TooltipType.PickPerson)"  data-tooltip-url="@Url.Action("GetGenericTooltip", "Tooltip")" data-tooltip-id="genericTooltip" >&nbsp;</span>
				}
				</li>
		}
		else
		{
			<li class="reader">
				Available for reading
				<span class="icon smallIcon smallEditIcon" data-state="@((int)SubscribeState.Reader)" data-postback="@Url.Action("AddSubscriptionAdmin", "Library")" data-tooltip-type="@((int)TooltipType.PickPerson)"  data-tooltip-url="@Url.Action("GetGenericTooltip", "Tooltip")" data-tooltip-id="genericTooltip" >&nbsp;</span>
			</li>
		}
		
		<li class="@(Model.HistoryListMode == ListMode.Show ? "" : "hidden")"><ul>

		@foreach (var historySubscription in Model.HistoryList)
		{
			<li data-subscription-set="@historySubscription.SubscriptionSet">
				@GeneratePersonPanel(historySubscription, false)
			</li>
		}
		</ul></li>
	</ul>
	
	@if (Model.HistoryList.Any())
	{
		<div class="listIconContainer">
			<span class="@("icon " + (Model.HistoryListMode == ListMode.Show ? "openedListIcon" : "closedListIcon"))">&nbsp;</span>
		</div>
	}
</div>

<div class="peopleWrapper">
	
	<div class="listTitle">Waiting:</div>

	<ul class="peopleList" data-list-mode="@((int)Model.WaitingListMode)" data-list-name="waitingList">
	
	
	@if (Model.WaitingList.Any())
	{
		<li data-subscription-set="@Model.WaitingList.First().SubscriptionSet">
			@GeneratePersonPanel(Model.WaitingList.ElementAt(0),true)
		</li>
	}
	else
	{
		<li>
			None
		</li>
	}
	

	<li class="@(Model.WaitingListMode == ListMode.Show ? "" : "hidden")"><ul>
	
	@for (int index = 1; index < Model.WaitingList.Count(); index++)
	{
		<li data-subscription-set="@Model.WaitingList.ElementAt(index).SubscriptionSet">
			@GeneratePersonPanel(Model.WaitingList.ElementAt(index),true)
		</li>
	}

	</ul></li>
	</ul>
	
	@if (Model.WaitingList.Count() > 1)
	{
		<div class="listIconContainer">
			<span class="@("icon " + (Model.WaitingListMode == ListMode.Show ? "openedListIcon" : "closedListIcon"))">&nbsp;</span>
		</div>
	}
</div>

	@if (Model.CanAddInWaitingList)
	{
		<span class="icon waitingListIconPosition waitingListActiveIcon" data-state="@((int)SubscribeState.Waiting)" data-postback="@Url.Action("AddSubscriptionCommon", "Library")" data-tooltip-type="@((int)TooltipType.AddYourselfToWaitingList)" data-tooltip-url="@Url.Action("GetGenericTooltip", "Tooltip")" data-tooltip-id="genericTooltip">&nbsp;</span>
	}
	else
	{
		<span class="icon waitingListIconPosition waitingListInactiveIcon">&nbsp;</span>
	}

</div>